package com.zh.repo.common;

import com.zh.repo.entity.vo.BakeOvenInfo;
import com.zh.repo.entity.vo.BakeOvenInfoView;
import com.zh.repo.service.BakeOvenInfoService;
import com.zh.repo.util.CalendarUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @description: 烘箱使用信息的操作类
 * @author:
 * @time: 2025-05-11 11:57
 * @version: 1.0
 */
@Slf4j
@Component
public class BakeOvenInfoMethods {
    @Resource
    private BakeOvenInfoService bakeOvenInfoService;

    public static BakeOvenInfoMethods bakeOvenInfoMethods;

    @PostConstruct
    public void init(){
        bakeOvenInfoMethods=this;
        bakeOvenInfoMethods.bakeOvenInfoService=this.bakeOvenInfoService;
    }

    public static List<BakeOvenInfoView> getBakeOvenInfoViewFrontList(Map map) throws ParseException {
       // log.info("=待运行的map参数：=>{}<==",map);
        List<BakeOvenInfoView> bakeOvenInfoListObject =bakeOvenInfoMethods.bakeOvenInfoService.getBakeOvenInfoViewList(map);
        // log.info("查询后的返回BakeOvenInfo的list结果：{}<==", bakeOvenInfoListObject);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String strDate= (String) map.get("yearMontKsrq");
        List<BakeOvenInfoView> bakeOvenInfoListDay = CalendarUtil.getDayListOfMonthToBakeOvenInfoView(strDate);

        List<BakeOvenInfoView> bakeOvenInfoListResult=new ArrayList<>();
        for(int i = 0; i< bakeOvenInfoListDay.size(); i++){
            BakeOvenInfoView outBakeOven= bakeOvenInfoListDay.get(i);
            Date outDate=sdf.parse(outBakeOven.getKsrq());
            for(int j = 0; j< bakeOvenInfoListObject.size(); j++){
                BakeOvenInfoView innerBakOven= bakeOvenInfoListObject.get(j);
                Date innerDate= sdf.parse(innerBakOven.getKsrq());
                if(innerDate.equals(outDate)){
                    outBakeOven.setStrPJ(innerBakOven.getStrPJ());
                }
            }
            bakeOvenInfoListResult.add(outBakeOven);
        }
        //log.info("=转换后的日历对象=>{}<==",bakeOvenInfoListResult);
        return bakeOvenInfoListResult;
    }

    //依据所传查询条件，获取返回List用于前端显示(日期值不可为空）
    public static List<BakeOvenInfo> getBakeOvenInfoFrontList(Map map) throws ParseException {
        log.info("=待运行的map参数：=>{}<==",map);
        List<BakeOvenInfo> bakeOvenInfoListObject =bakeOvenInfoMethods.bakeOvenInfoService.getBakeOvenInfoList(map);
        // log.info("查询后的返回BakeOvenInfo的list结果：{}<==", bakeOvenInfoListObject);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String strDate= (String) map.get("yearMontKsrq");
        List<BakeOvenInfo> bakeOvenInfoListDay = CalendarUtil.getDayListOfMonthToBakeOven(strDate);

        List<BakeOvenInfo> bakeOvenInfoListResult=new ArrayList<>();
        for(int i = 0; i< bakeOvenInfoListDay.size(); i++){
            BakeOvenInfo outBakeOven= bakeOvenInfoListDay.get(i);
            Date outDate=sdf.parse(outBakeOven.getKsrq());
            for(int j = 0; j< bakeOvenInfoListObject.size(); j++){
                BakeOvenInfo innerBakOven= bakeOvenInfoListObject.get(j);
                Date innerDate= sdf.parse(innerBakOven.getKsrq());
                if(innerDate.equals(outDate)){
                    outBakeOven.setUserName(innerBakOven.getUserName());
                    outBakeOven.setUserDepartment(innerBakOven.getUserDepartment());
                    outBakeOven.setKssj(innerBakOven.getKssj());
                    outBakeOven.setJsrq(innerBakOven.getJsrq());
                    outBakeOven.setJssj(innerBakOven.getJssj());
                    outBakeOven.setBakeOvenName(innerBakOven.getBakeOvenName());
                    outBakeOven.setSqrq(innerBakOven.getSqrq());
                    outBakeOven.setCsyq(innerBakOven.getCsyq());
                    outBakeOven.setRequestId(innerBakOven.getRequestId());
                }
            }
            bakeOvenInfoListResult.add(outBakeOven);
        }
        log.info("=转换后的日历对象=>{}<==",bakeOvenInfoListResult);
        return bakeOvenInfoListResult;
    }
}
